<?php
	// No direct access
	defined('_JEXEC') or die;
    jimport( 'joomla.application.component.view');
    class VolunteerViewSearchfile extends JView
    {
		function display($tpl = null)
		{
			$model = $this->getModel('volunteer');
			
			//list all locations, timespans and industries
			$this->assignRef( 'locations', $model->getLocations() );
			$this->assignRef( 'timespans', $model->getTimespans() );
			$this->assignRef( 'industries', $model->getIndustries() );
			
			//get POST/GET parameters' value
			$selectedLocation = JRequest::getVar('location');
			if($selectedLocation)
			{
				$selectedTimespan = JRequest::getVar('timespan');
				if(!$selectedTimespan) $selectedTimespan = -1; //all timespans
				$selectedIndustry = JRequest::getVar('industry');
				if(!$selectedIndustry) $selectedIndustry = -1; //all industries
				$enteredKeywords = JRequest::getVar('keywords');
				if(!$enteredKeywords) $enteredKeywords = '';
				
				$this->assignRef( 'selectedLocation', $selectedLocation );
				$this->assignRef( 'selectedTimespan', $selectedTimespan );
				$this->assignRef( 'selectedIndustry', $selectedIndustry );				
				$this->assign( 'enteredKeywords', $enteredKeywords );				
				
				$result = $model->searchFile($selectedLocation, $selectedTimespan, $selectedIndustry, $enteredKeywords );
				$this->assign( 'results', $result);
				// $this->assign( 'results', $model->getData());
				$this->assign( 'pagination', $model->getPagination());
				$this->assign( 'totalFile', sizeof($result));
			}
			
			parent::display($tpl); //display defaul template
		}
    }